package com.dal.db.bean;

import static com.dal.db.StaticResource.PlatformResource.*;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.dal.db.cache.PlatformCache;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import com.dal.db.cache.AccountCache;
import static com.dal.db.StaticResource.PlatformResource.*;
/**
 * 平台
 */
public class Platform extends BasePojo<Platform> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 平台名称
	*/
	private String platFormName;
	
	/**
	* 参数检测器类型
	*/
	private int paramCheckerType;
	
	/**
	* 平台账号校验器类型
	*/
	private int verifyerType;
	
	/**
	* 账号创建器类型
	*/
	private int accountCreatorType;
	
	
	@Deprecated
	public static Platform builder() {
		Platform platform = new Platform();
		return platform;
	}
	
	@Deprecated
	public Platform() {
		super();
	}
	
	public Platform(int id, String platFormName, int paramCheckerType, int verifyerType, int accountCreatorType) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.platFormName = platFormName;
		this.paramCheckerType = paramCheckerType;
		this.verifyerType = verifyerType;
		this.accountCreatorType = accountCreatorType;
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public Platform setId(int id) {this.id = id;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Platform setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Platform setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 平台名称
	 */
	public String getPlatFormName() {return platFormName;}
	
	/**
	 * 平台名称
	 */
	public Platform setPlatFormName(String platFormName) {this.platFormName = platFormName;return this;}
	
	/**
	 * 参数检测器类型
	 */
	public int getParamCheckerType() {return paramCheckerType;}
	
	/**
	 * 参数检测器类型
	 */
	public Platform setParamCheckerType(int paramCheckerType) {this.paramCheckerType = paramCheckerType;return this;}
	
	/**
	 * 平台账号校验器类型
	 */
	public int getVerifyerType() {return verifyerType;}
	
	/**
	 * 平台账号校验器类型
	 */
	public Platform setVerifyerType(int verifyerType) {this.verifyerType = verifyerType;return this;}
	
	/**
	 * 账号创建器类型
	 */
	public int getAccountCreatorType() {return accountCreatorType;}
	
	/**
	 * 账号创建器类型
	 */
	public Platform setAccountCreatorType(int accountCreatorType) {this.accountCreatorType = accountCreatorType;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.platFormName;
        values[4] = this.paramCheckerType;
        values[5] = this.verifyerType;
        values[6] = this.accountCreatorType;
        return values;
	}
	
	public Platform deepCopy(){
		Platform platform = null;
		try {
			platform = (Platform) super.clone();
		    platform.setCreateDate(ToolCopy.copyObject(this.createDate));
		    platform.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    platform.indexValues = ArrayUtils.clone(indexValues);
			return platform;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return platform;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.platFormName);
        map.put(keys[4], this.paramCheckerType);
        map.put(keys[5], this.verifyerType);
        map.put(keys[6], this.accountCreatorType);
        return map;
    }
    
    protected Platform createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.platFormName = (String)map.get(keys[3]);
   		this.paramCheckerType = (int)map.get(keys[4]);
   		this.verifyerType = (int)map.get(keys[5]);
   		this.accountCreatorType = (int)map.get(keys[6]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.platFormName);
        obj.put(keys[4], this.paramCheckerType);
        obj.put(keys[5], this.verifyerType);
        obj.put(keys[6], this.accountCreatorType);
        return obj;
    }
    
    protected Platform createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.platFormName = obj.getString(keys[3]);
	    this.paramCheckerType = obj.getIntValue(keys[4]);
	    this.verifyerType = obj.getIntValue(keys[5]);
	    this.accountCreatorType = obj.getIntValue(keys[6]);
        return this;
    }
    
    
    public Platform createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.platFormName = rs.getString(SOURCE_COLUMN_NAMES[3]);
	    this.paramCheckerType = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    this.verifyerType = rs.getInt(SOURCE_COLUMN_NAMES[5]);
	    this.accountCreatorType = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeString(this.platFormName);
	    byteBuf.writeInt(this.paramCheckerType);
	    byteBuf.writeInt(this.verifyerType);
	    byteBuf.writeInt(this.accountCreatorType);
    }
	
	protected Platform readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.platFormName = byteBuf.readString(null);
	    this.paramCheckerType = byteBuf.readInt(null);
	    this.verifyerType = byteBuf.readInt(null);
	    this.accountCreatorType = byteBuf.readInt(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Platform insert(){
    	return PlatformCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Platform update(){
    	return PlatformCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return PlatformCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Platform insertAndFlush(){
    	return PlatformCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Platform updateAndFlush(){
    	return PlatformCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return PlatformCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Platform syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}